package com.infoauto.opc.gateway.messages.factory;


import com.infoauto.opc.gateway.messages.binder.RabbitMQBinder;
import com.infoauto.opc.gateway.messages.enums.ExchangeType;
import com.infoauto.opc.gateway.messages.handler.RabbitMQListener;
import com.infoauto.opc.gateway.messages.model.RabbitMQConsumer;
import com.infoauto.opc.gateway.messages.model.RabbitMQSender;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;


public class RabbitMQFactory {

    private static ConnectionFactory connectionFactory;

    public RabbitMQFactory(ConnectionFactory connectionFactory) {
        RabbitMQFactory.connectionFactory = connectionFactory;
    }

    //交换器类型Fanout
    public static RabbitMQSender createFanoutSender(String exchangeName, String queueName) {
        return createSender(connectionFactory, exchangeName, null, queueName, ExchangeType.FANOUT);
    }

   //交换器类型Direct
    public static RabbitMQSender createDirectSender(String queueName) {
        return createSender(connectionFactory, queueName, queueName, queueName, ExchangeType.DIRECT);
    }

   //交换器类型Topic
    public static RabbitMQSender createTopicSender(String exchangeName, String routingKey, String queueName) {
        return createSender(connectionFactory, exchangeName, routingKey, queueName, ExchangeType.TOPIC);
    }

    public static RabbitMQSender createSender(ConnectionFactory connectionFactory, String exchangeName,
                                              String routingKey, String queueName, ExchangeType exchangeType) {
        RabbitMQSender rabbitMQSender = new RabbitMQSender(connectionFactory, exchangeName, routingKey, queueName,
                exchangeType);
        rabbitMQSender.build();
        return rabbitMQSender;
    }


    public static RabbitMQSender createSender(ConnectionFactory connectionFactory, String exchangeName, String routingKey) {
        return new RabbitMQSender(connectionFactory, exchangeName, routingKey);
    }

  
    public static RabbitMQSender createSender(String exchangeName, String routingKey) {
        return new RabbitMQSender(connectionFactory, exchangeName, routingKey);
    }

  
    public static RabbitMQConsumer createConsumer(String queueName, RabbitMQListener rabbitMQListener) {
        return createConsumer(connectionFactory, queueName, rabbitMQListener);
    }

 
    public static RabbitMQConsumer createConsumer(ConnectionFactory connectionFactory, String queueName,
                                                  RabbitMQListener rabbitMQListener) {
        return new RabbitMQConsumer(connectionFactory, queueName, rabbitMQListener);
    }

    //绑定器
    public static RabbitMQBinder createBinder(ConnectionFactory connectionFactory){
        return new RabbitMQBinder(connectionFactory);
    }

    public static RabbitMQBinder createBinder(){
        return new RabbitMQBinder(connectionFactory);
    }
}
